class Queue{
    constructor(){
        this.count=0
        this.lowestcount=0
        this.items={}
    }
    size(){
        return this.count-this.lowestcount
    }
    isEmpty(){
        return this.size()===0
    }
    enqueue(element){
        this.items[this.count]=element
        this.count++
    }
    dequeue(){
        if (this.isEmpty()) {
            return undefined
        }
        const result=this.items[this.lowestcount]
        delete this.items[this.lowestcount]
        this.lowestcount++
        return result
    }
    peek(){
        if (this.isEmpty()) {
            return undefined
        }
        return thiss.items[this.lowestcount]
    }
    clear(){
        this.count=0
        this.lowestcount=0
        this.items={}
    }
    toString(){
        if (this.isEmpty()) {
            return ''
        }
        let objstr=this.items[this.lowestcount]
        for(let i=this.lowestcount+1;i<this.count;i++){
            objstr=`${objstr},${this.items[i]}`
        }
        return objstr
    }
}
function jiguchuanhua(player,num) {
    const queue=new Queue()
    for (let i = 0; i < player.length; i++) {
        queue.enqueue(player[i])
    }
    while(queue.size()>1){
        for (let i = 0; i < num;i++) {
          queue.enqueue(queue.dequeue())
        }
        const name=queue.dequeue()
        console.log(name+'被淘汰了');
    }
    const winner=queue
    console.log('胜利者是'+winner);
    return winner
}

const player=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
jiguchuanhua(player,3)